// 传入两个参数，其中第二个参数受到第一个参数的约束
function getProp<Type, Key extends keyof Type>(obj: Type, key: Key) {
  return obj[key]
}

console.log(getProp({ name: 'zhangsan', age: 18 }, 'name'))
console.log(getProp({ name: 'zhangsan', age: 18 }, 'age'))

console.log(getProp([1,3,4], 'length'))
console.log(getProp('avbcads', 'toString'))
console.log(getProp('avbcads', 0))
console.log(getProp(123, 'toString')) // number对象的toString方法,123['toString'] 返回了该方法本身